define(['jquery','api','user','util'],function($,api,user,util){
	var vm,
	   controller = {
	   init:function(id){
	   	   if(!user.checkLogin())return;
		   api.initFooter(3);
		   api.setTitle('佣金分成');
		   if(!vm){
		     this.render();
		   }else{
		     vm.show=true;
		   }
	   },
	   render:function(){
	   		var that = this;
	   	   $('#pages').append('<div id="commission"></div>');
	       require(['text!pages/user/commission.html','Vue'],function(tpl,Vue){
	            vm=new Vue({
	               el:'#commission',
	               data:{
	               	  show:true,
	               	  rows:[],
	               	  sumCount:'--',
	               	  sumCharge:'--',
	               	  sumShareCharge:'--',
	               	  form:{
	               	  	username:'',
	               	  	startTime:(function(d){d.setMonth(d.getMonth()-1);return d.format('yyyy-MM-dd')})(new Date()),
    		            endTime:(function(d){return d.format('yyyy-MM-dd')})(new Date())
	               	  }
	               },
	               methods:{
	                  doQuery:function(){
	                  	 var data={
	                  	 	username:this.form.username,
	                  	    starttradingday:this.form.startTime,
	                  	    returnresulttype:49,
	                  	    pagestart:1,
	                  	    count:10000,
	                  	    endtradingday:this.form.endTime
	                  	 }
	                  	 
	                  	 if(!data.username){
	                  	 	util.msg('请输入账户名称');
	                  	 	return;
	                  	 }
	                  	 
	                  	 that.loading('show');
	                     api.commission(data,function(rs){
	                     	that.loading('hide');
	                         if(rs.retcode=='0' && rs.hisagentuserres){
	                            vm.sumCount=rs.hisagentuserres.sumcount;
	                            vm.sumCharge=rs.hisagentuserres.sumcharge;
	                            vm.sumShareCharge=rs.hisagentuserres.sumsharecharge;
	                         }else{
	                         	util.msg('暂无更多数据');
	                         }
	                     })
	                  }
	               },
	               template:tpl
	            })
	       })
	   },
	   loading:function(type){
	   	if(type==='show'){
	   		$("#loading").show();
	   	}else if(type==='hide'){
	   		$("#loading").hide();
	   	}
	   },
	   onRouteChange:function(){
	       if(vm)vm.show=false;
	   }
	};
    return controller;
})